﻿/*----------------------------------------------------------------
//  <copyright file="Knife4jOptions.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2022-11-15 15:50</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.Swagger.Knife4j
{
    #region "Knife4j配置选项"
    /// <summary>
    /// Knife4j配置选项
    /// </summary>
    public class Knife4jOptions
    {
        #region "属性"
        #region "获取或设置 用于访问swagger ui的路由前缀"
        /// <summary>
        /// 获取或设置 用于访问swagger ui的路由前缀
        /// Gets or sets a route prefix for accessing the swagger-ui
        /// </summary>
        public string RoutePrefix { get; set; } = "swagger";
        #endregion
        #region "获取或设置 用于检索swagger ui页面的Stream函数"
        private Func<Stream> _IndexStream = null;
        /// <summary>
        /// 获取或设置 用于检索swagger ui页面的Stream函数
        /// Gets or sets a Stream function for retrieving the swagger-ui page
        /// </summary>
        public Func<Stream> IndexStream
        {
            get
            {
                if (_IndexStream != null)
                {
                    return _IndexStream;
                }
                if (MiniProfiler)
                {
                    _IndexStream = () => typeof(Knife4jOptions).GetTypeInfo().Assembly.GetManifestResourceStream("MicroCloud.Swagger.Knife4j.dist_miniprofiler.doc.html");
                }
                else
                {
                    _IndexStream = () => typeof(Knife4jOptions).GetTypeInfo().Assembly.GetManifestResourceStream("MicroCloud.Swagger.Knife4j.dist.doc.html");
                }
                return _IndexStream;
            }
            set
            {
                _IndexStream = value;
            }
        }
        #endregion
        #region "获取或设置 swagger ui页面的标题"
        /// <summary>
        /// 获取或设置 swagger ui页面的标题
        /// Gets or sets a title for the swagger-ui page
        /// </summary>
        public string DocumentTitle { get; set; } = "Knife4j UI";
        #endregion
        #region "获取或设置 放置在swagger ui页面首部的其他内容"
        /// <summary>
        /// 获取或设置 放置在swagger ui页面首部的其他内容
        /// Gets or sets additional content to place in the head of the swagger-ui page
        /// </summary>
        public string HeadContent { get; set; } = "";
        #endregion
        #region "获取或设置 JavaScript配置对象，表示为JSON，该对象将传递给Knife4jUI"
        /// <summary>
        /// 获取或设置 JavaScript配置对象，表示为JSON，该对象将传递给Knife4jUI
        /// Gets the JavaScript config object, represented as JSON, that will be passed to the Knife4jUI
        /// </summary>
        public ConfigObject ConfigObject { get; set; } = new ConfigObject();
        #endregion
        #region "获取或设置 启用轻量级工具分析"
        /// <summary>
        /// 获取或设置 启用轻量级工具分析
        /// </summary>
        public bool MiniProfiler { get; set; } = false;
        #endregion

        #region "获取或设置 传递给initOAuth方法的JavaScript配置对象（表示为JSON）"
        /// <summary>
        /// 获取或设置 传递给initOAuth方法的JavaScript配置对象（表示为JSON）
        /// Gets the JavaScript config object, represented as JSON, that will be passed to the initOAuth method
        /// </summary>
        //[Obsolete("暂不支持此特性")]
        public OAuthConfigObject OAuthConfigObject { get; set; } = new OAuthConfigObject();
        #endregion

        #region "获取或设置 定义客户端请求/响应拦截器的拦截器函数"
        /// <summary>
        /// 获取或设置 定义客户端请求/响应拦截器的拦截器函数
        /// Gets the interceptor functions that define client-side request/response interceptors
        /// </summary>
        public InterceptorFunctions Interceptors { get; set; } = new InterceptorFunctions();
        #endregion

        #endregion

    }
    #endregion

    #region "JavaScript配置对象，表示为JSON，该对象将传递给Knife4jUI"
    /// <summary>
    /// JavaScript配置对象，表示为JSON，该对象将传递给Knife4jUI
    /// JavaScript config object, represented as JSON, that will be passed to the Knife4jUI
    /// </summary>
    public class ConfigObject
    {
        #region "属性"
        #region "获取或设置 一个或多个Swagger JSON端点（url和名称）来支持UI"
        /// <summary>
        /// 获取或设置 一个或多个Swagger JSON端点（url和名称）来支持UI
        /// One or more Swagger JSON endpoints (url and name) to power the UI
        /// </summary>
        public IEnumerable<UrlDescriptor> Urls { get; set; } = null;
        #endregion
        #region "获取或设置 如果设置为true，则启用标记和操作的深度链接"
        /// <summary>
        /// 获取或设置 如果设置为true，则启用标记和操作的深度链接
        /// If set to true, enables deep linking for tags and operations
        /// </summary>
        public bool DeepLinking { get; set; } = false;
        #endregion
        #region "获取或设置 控制操作列表中operationId的显示"
        /// <summary>
        /// 获取或设置 控制操作列表中operationId的显示
        /// Controls the display of operationId in operations list
        /// </summary>
        public bool DisplayOperationId { get; set; } = false;
        #endregion
        #region "获取或设置 模型的默认展开深度（设置为-1完全隐藏模型）"
        /// <summary>
        /// 获取或设置 模型的默认展开深度（设置为-1完全隐藏模型）
        /// The default expansion depth for models (set to -1 completely hide the models)
        /// </summary>
        public int DefaultModelsExpandDepth { get; set; } = 1;
        #endregion
        #region "获取或设置 模型示例部分中模型的默认展开深度"
        /// <summary>
        /// 获取或设置 模型示例部分中模型的默认展开深度
        /// The default expansion depth for the model on the model-example section
        /// </summary>
        public int DefaultModelExpandDepth { get; set; } = 1;
        #endregion
        #region "获取或设置 控制首次渲染API时模型的显示方式。"
        /// <summary>
        /// 获取或设置 控制首次渲染API时模型的显示方式。
        /// Controls how the model is shown when the API is first rendered.
        /// (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links)
        /// </summary>
        public ModelRendering DefaultModelRendering { get; set; } = ModelRendering.Example;
        #endregion
        #region "获取或设置 控制“试用”请求的请求持续时间（毫秒）的显示"
        /// <summary>
        /// 获取或设置 控制“试用”请求的请求持续时间（毫秒）的显示
        /// Controls the display of the request duration (in milliseconds) for Try-It-Out requests
        /// </summary>
        public bool DisplayRequestDuration { get; set; } = false;
        #endregion
        #region "获取或设置 控制操作和标记的默认展开设置。"
        /// <summary>
        /// 获取或设置 控制操作和标记的默认展开设置。
        /// Controls the default expansion setting for the operations and tags.
        /// It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing)
        /// </summary>
        public DocExpansion DocExpansion { get; set; } = DocExpansion.List;
        #endregion
        #region "获取或设置 启用过滤"
        /// <summary>
        /// 获取或设置 启用过滤
        /// If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations
        /// that are shown. Can be an empty string or specific value, in which case filtering will be enabled using that
        /// value as the filter expression. Filtering is case sensitive matching the filter expression anywhere inside the tag
        /// </summary>
        public string Filter { get; set; } = null;
        #endregion
        #region "获取或设置 显示的标记操作的数量限制为最多此数量。默认值是显示所有操作"
        /// <summary>
        /// 获取或设置 显示的标记操作的数量限制为最多此数量。默认值是显示所有操作
        /// If set, limits the number of tagged operations displayed to at most this many. The default is to show all operations
        /// </summary>
        public int? MaxDisplayedTags { get; set; } = null;
        #endregion
        #region "获取或设置 控制“操作”、“参数”和“架构”的供应商扩展（x-）字段和值的显示"
        /// <summary>
        /// 获取或设置 控制“操作”、“参数”和“架构”的供应商扩展（x-）字段和值的显示
        /// Controls the display of vendor extension (x-) fields and values for Operations, Parameters, and Schema
        /// </summary>
        public bool ShowExtensions { get; set; } = false;
        #endregion
        #region "获取或设置 控制参数的扩展（模式、最大长度、最小长度、最大值、最小值）字段和值的显示"
        /// <summary>
        /// 获取或设置 控制参数的扩展（模式、最大长度、最小长度、最大值、最小值）字段和值的显示
        /// Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters
        /// </summary>
        public bool ShowCommonExtensions { get; set; } = false;
        #endregion
        #region "获取或设置 OAuth重定向URL"
        /// <summary>
        /// 获取或设置 OAuth重定向URL
        /// OAuth redirect URL
        /// </summary>
        [JsonPropertyName("oauth2RedirectUrl")]
        public string OAuth2RedirectUrl { get; set; } = null;
        #endregion
        #region "获取或设置 启用了“提交”功能的HTTP方法列表。"
        /// <summary>
        /// 获取或设置 启用了“提交”功能的HTTP方法列表。
        /// List of HTTP methods that have the Try it out feature enabled.
        /// An empty array disables Try it out for all operations. This does not filter the operations from the display
        /// </summary>
        public IEnumerable<SubmitMethod> SupportedSubmitMethods { get; set; } = Enum.GetValues(typeof(SubmitMethod)).Cast<SubmitMethod>();
        #endregion
        #region "获取或设置 验证程序URL"
        /// <summary>
        /// 获取或设置 验证程序URL
        /// By default, Swagger-UI attempts to validate specs against swagger.io's online validator.
        /// You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge).
        /// Setting it to null will disable validation
        /// </summary>
        public string ValidatorUrl { get; set; } = null;
        #endregion
        #region "获取或设置 其他项目"
        /// <summary>
        /// 获取或设置 其他项目
        /// </summary>
        [JsonExtensionData]
        public Dictionary<string, object> AdditionalItems { get; set; } = new Dictionary<string, object>();
        #endregion

        #endregion

    }
    #endregion

    #region "Url描述包装"
    /// <summary>
    /// Url描述包装
    /// </summary>
    public class UrlDescriptor
    {
        #region "属性"
        #region "获取或设置 Url"
        /// <summary>
        /// 获取或设置 Url
        /// </summary>
        public string Url { get; set; }
        #endregion
        #region "获取或设置 名称"
        /// <summary>
        /// 获取或设置 名称
        /// </summary>
        public string Name { get; set; }
        #endregion
        #region "获取或设置 Swagger版本"
        /// <summary>
        /// 获取或设置 Swagger版本
        /// </summary>
        public string SwaggerVersion { get; set; } = "3.0";
        #endregion

        #endregion

    }
    #endregion

    #region "模型渲染枚举"
    /// <summary>
    /// 模型渲染枚举
    /// </summary>
    public enum ModelRendering
    {
        /// <summary>
        /// 实例
        /// </summary>
        Example,
        /// <summary>
        /// 模型
        /// </summary>
        Model
    }
    #endregion

    #region "文档扩展枚举"
    /// <summary>
    /// 文档扩展枚举
    /// </summary>
    public enum DocExpansion
    {
        /// <summary>
        /// 列表
        /// </summary>
        List,
        /// <summary>
        /// 全部
        /// </summary>
        Full,
        /// <summary>
        /// 无
        /// </summary>
        None
    }
    #endregion

    #region "提交方法枚举"
    /// <summary>
    /// 提交方法枚举
    /// </summary>
    public enum SubmitMethod
    {
        /// <summary>
        /// Get
        /// </summary>
        Get,
        /// <summary>
        /// Put
        /// </summary>
        Put,
        /// <summary>
        /// Post
        /// </summary>
        Post,
        /// <summary>
        /// Delete
        /// </summary>
        Delete,
        /// <summary>
        /// Options
        /// </summary>
        Options,
        /// <summary>
        /// Head
        /// </summary>
        Head,
        /// <summary>
        /// Patch
        /// </summary>
        Patch,
        /// <summary>
        /// Trace
        /// </summary>
        Trace
    }
    #endregion

    #region "OAuth配置对象"
    /// <summary>
    /// OAuth配置对象
    /// </summary>
    public class OAuthConfigObject
    {
        /// <summary>
        /// Default clientId
        /// </summary>
        public string ClientId { get; set; } = null;

        /// <summary>
        /// Default clientSecret
        /// </summary>
        public string ClientSecret { get; set; } = null;

        /// <summary>
        /// Realm query parameter (for oauth1) added to authorizationUrl and tokenUrl
        /// </summary>
        public string Realm { get; set; } = null;

        /// <summary>
        /// Application name, displayed in authorization popup
        /// </summary>
        public string AppName { get; set; } = null;

        /// <summary>
        /// Scope separator for passing scopes, encoded before calling, default value is a space (encoded value %20)
        /// </summary>
        public string ScopeSeparator { get; set; } = " ";

        /// <summary>
        /// Additional query parameters added to authorizationUrl and tokenUrl
        /// </summary>
        public Dictionary<string, string> AdditionalQueryStringParams { get; set; } = null;

        /// <summary>
        /// Only activated for the accessCode flow. During the authorization_code request to the tokenUrl,
        /// pass the Client Password using the HTTP Basic Authentication scheme
        /// (Authorization header with Basic base64encode(client_id + client_secret))
        /// </summary>
        public bool UseBasicAuthenticationWithAccessCodeGrant { get; set; } = false;

        /// <summary>
        /// Only applies to authorizatonCode flows. Proof Key for Code Exchange brings enhanced security for OAuth public clients.
        /// The default is false
        /// </summary>
        public bool UsePkceWithAuthorizationCodeGrant { get; set; } = false;
    }
    #endregion

}